//
//  LYMyBankView.m
//  SZBank
//
//  Created by LuoYao on 16/7/9.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "LYMyBankView.h"
#import "LYScheduleView.h"
#import "LYMemorialView.h"
#import "LYAddressBookView.h"
#import "LYFestivalView.h"
#import "LYPgwbView.h"

@interface LYMyBankView ()<CustomerNavigationBarsDelegate>
{
    CGFloat _cKwidth,_cKheight;/**< 当前视图的宽度和高度，不是屏幕宽度和高度 */
    NSInteger _index;/**< 上次选中页面 */
}
@property (nonatomic) CustomerNavigationBars *navagiationBarsView;

@end
@implementation LYMyBankView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //宽度和高度
        _cKwidth = frame.size.width;
        _cKheight = frame.size.height;
        
        //背景图
        UIImageView *backImage = [[UIImageView alloc] initWithFrame:self.bounds];
        backImage.image = [LocalDataManager getImageWithSourceOfPath:@"背景"];
        
        [backImage setContentMode:UIViewContentModeScaleAspectFit];
        [self addSubview:backImage];
        
        self.titleArray = @[@"日程安排",@"备忘录",@"通讯录",@"历史节日贺卡",@"问卷调查"];
        
        //导航条
        [self addSubview:self.navagiationBarsView];
        
        
        //默认第一个页面
        LYScheduleView *chedu = [[LYScheduleView alloc] initWithFrame:CGRectMake(_cKwidth * 0.03, CGRectGetMaxY(self.navagiationBarsView.frame), _cKwidth * 0.94, _cKheight * 0.9)];
        [self addSubview:chedu];
        
       
    }
    return self;
}




#pragma mark - 导航条协议方法
- (void)customeNavigationBarView:(CustomerNavigationBars *)customeNavigationBarView didSelectButton:(UIButton *)didSelectButton{
    if (_index == didSelectButton.tag - 1000) {
        return;
    }
    
    //移除其他视图
    NSArray *array = self.subviews;
    
    for (UIView *ve in array) {
        if ([ve isKindOfClass:[LYMyBankBaseView class]]) {
            [ve removeFromSuperview];
        }
    }
    
    
    switch (didSelectButton.tag - 1000) {
        case 0:
        {
            LYScheduleView *chedu = [[LYScheduleView alloc] initWithFrame:CGRectMake(_cKwidth * 0.03, CGRectGetMaxY(self.navagiationBarsView.frame), _cKwidth * 0.94, _cKheight * 0.9)];
            
            [self addSubview:chedu];
        }
            break;
            
        case 1:{
            LYMemorialView *mem = [[LYMemorialView alloc] initWithFrame:CGRectMake(_cKwidth * 0.03, CGRectGetMaxY(self.navagiationBarsView.frame), _cKwidth * 0.94, _cKheight * 0.9)];
            
            [self addSubview:mem];
        }
            break;
            
        case 2:{
            LYAddressBookView *address = [[LYAddressBookView alloc]initWithFrame:CGRectMake(_cKwidth * 0.03, CGRectGetMaxY(self.navagiationBarsView.frame), _cKwidth * 0.94, _cKheight * 0.9)];
            
            [self addSubview:address];
        }
            break;
            
        case 3:{
            //网络请求
            [NetWorkingDataManager getProtocolCardWithParam:nil success:^(id sender) {
              NSArray  *array = sender[@"datalist"];
                
                LYFestivalView *festival = [[LYFestivalView alloc] initWithFrame:CGRectMake(_cKwidth * 0.03, CGRectGetMaxY(self.navagiationBarsView.frame), _cKwidth * 0.94, _cKheight * 0.9) topImageNames:array];
                
                [self addSubview:festival];
                
            } failure:^(id sender) {
                
            }];
            
            
        }
            break;
            
        case 4:{
            
            [NetWorkingDataManager getPgwbListWithSuccess:^(id sender) {
                
                LYPgwbView *pgwb = [[LYPgwbView alloc] initWithFrame:CGRectMake(_cKwidth * 0.03, CGRectGetMaxY(self.navagiationBarsView.frame), _cKwidth * 0.94, _cKheight * 0.9) withArray:sender];
                
                [self addSubview:pgwb];
                
            } failure:^(id sender) {
                
            }];
            
            
        }
            break;
            
        default:
            break;
    }
    
    _index = didSelectButton.tag - 1000;
    
}



#pragma mark - getter
- (CustomerNavigationBars *)navagiationBarsView{
    if (!_navagiationBarsView) {
        _navagiationBarsView = [[CustomerNavigationBars alloc] initWithFrame:CGRectMake(0, _cKheight * 0.01, _cKwidth, _cKheight * 0.06) btnTitleArray:self.titleArray];
        _navagiationBarsView.delegate = self;
    }
    return _navagiationBarsView;
}

@end
